'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  // 上传模板
  async index() {
    const { ctx } = this;
    await ctx.render('upload', {
      title: '测试上传',
      filename: 'test-upload',
    });
  }

  // file 上传
  async getUploadFile() {
    const { ctx } = this;
    const fileObj = ctx.request.files[0];
    ctx.body = await ctx.service.upload.getUploadFile(fileObj);
  }

  // stream 上传
  async getUploadStream() {
    const { ctx } = this;
    const stream = await ctx.getFileStream();
    ctx.body = await ctx.service.upload.getUploadStream(stream);
  }
}

module.exports = HomeController;
